from selenium import webdriver
from selenium.webdriver.common.by import By
import time

class TestCase:

    def __init__(self):
        # 初始化对象属性
        self.driver = webdriver.Chrome()

    def get_ecshop(self,keyword,seconds=2):
        # 请求ecshop
        self.driver.get('https://ecshop.test2.shopex123.com')

        # 获取搜索框输入关键字
        time.sleep(seconds)
        self.driver.find_element(By.ID, 'keyword').send_keys(keyword)

        # 获取搜索按钮并点击
        time.sleep(seconds)
        self.driver.find_element(By.CLASS_NAME, 'btn_search').click()

    def register(self,username,email,password,confirm_password,seconds=2):
        # 请求ecshop
        self.driver.get('https://ecshop.test2.shopex123.com')
        # 点击注册选项
        time.sleep(seconds)
        self.driver.find_element(By.CLASS_NAME, 'reg').click()
        # 获取用户名搜索框
        time.sleep(seconds)
        self.driver.find_element(By.ID, 'username').send_keys(username)
        # 填写邮箱
        time.sleep(seconds)
        self.driver.find_element(By.ID, 'email').send_keys(email)
        # 输入密码
        time.sleep(seconds)
        self.driver.find_element(By.ID, 'password1').send_keys(password)
        # 确认密码
        time.sleep(seconds)
        self.driver.find_element(By.ID, 'confirm_password').send_keys(confirm_password)
        # 点击同意协议并注册按钮
        time.sleep(seconds)
        self.driver.find_element(By.CLASS_NAME, 'signup_button').click()

    def log_in(self,username,password,seconds=2):
        # 请求ecshop
        self.driver.get('https://ecshop.test2.shopex123.com')
        # 点击登录选项
        time.sleep(seconds)
        self.driver.find_element(By.CLASS_NAME, 'sign').click()
        # 获取用户名搜索框
        time.sleep(seconds)
        self.driver.find_element(By.NAME, 'username').send_keys(username)
        # 输入密码
        time.sleep(seconds)
        self.driver.find_element(By.NAME, 'password').send_keys(password)
        # 输入账号密码后点击登录
        time.sleep(seconds)
        self.driver.find_element(By.NAME, 'submit').click()

    def quit(self, seconds=3):
            time.sleep(seconds)
            self.driver.quit()

if __name__ == '__main__':
    case = TestCase()
    # case.get_ecshop('化妆')
    # case.register('vedolay','94298195@qq.com','wu123123','wu123123')
    case.log_in('vedolay','wu123123')
    case.quit()